home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASANS.ZIP / CH05_2.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-04  |  959b  |  41 lines

  1.                             (* Chapter 5 - Programming exercise 2 *)
  2. program Try_Recursion;
  3.  
  4. var Count : integer;
  5.  
  6. procedure Print_And_Decrement(Index : integer);
  7. begin
  8.    Writeln('The value of the index is ',Index:3);
  9.    Index := Index - 1;
  10.    if Index > 0 then
  11.       Print_And_Decrement(Index);
  12.    Writeln('The value of the index is now ',Index:3);
  13. end;
  14.  
  15. begin  (* main program *)
  16.    Count := 7;
  17.    Print_And_Decrement(Count);
  18. end.  (* main program *)
  19.  
  20.  
  21.  
  22.  
  23. { Result of execution
  24.  
  25. The value of the index is   7
  26. The value of the index is   6
  27. The value of the index is   5
  28. The value of the index is   4
  29. The value of the index is   3
  30. The value of the index is   2
  31. The value of the index is   1
  32. The value of the index in now 0
  33. The value of the index in now 1
  34. The value of the index in now 2
  35. The value of the index in now 3
  36. The value of the index in now 4
  37. The value of the index in now 5
  38. The value of the index in now 6
  39.  
  40. }
  41.